package com.hmkj.core.model.account;

import com.hmkj.core.exception.BussinessException;
import com.hmkj.core.po.account.AccountCash;
import com.hmkj.core.po.user.User;
import com.hmkj.core.po.userIdentify.UserIdentify;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Donfy on 2017/6/18.
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class CashModel extends AccountCash {

    private Integer userBankId;
    /**
     * 支付密码
     */
    private String payPassword;

    /**
     * 用户相关信息
     */
    private User u;
    /*
     * 认证信息
     */
    private UserIdentify ui;

    /**
     * 审核状态 1通过，2不通过
     */
    private Integer auditStatus;

    /**
     * 代付通道 1：连连，2九派，3华融
     */
    private Integer channel;


    public void checkCash() {
        if (getAmount() == null) {
            throw new BussinessException("提现金额不能为空");
        }
        if (getAmount().compareTo(BigDecimal.ZERO) != 1) {
            throw new BussinessException("提现金额必须大于0");
        }
    }

    public enum CHANNEL {

        /**
         * 1,连连支付:T1
         **/
        T1("连连支付", 1),

        /**
         * 2,九派支付:T2
         **/
        T2("九派支付", 2),

        /**
         * 3,华融支付:T3
         **/
        T3("华融支付", 3),

        /**
         * 4,联动优势:T4
         **/
        T4("联动优势", 4),

        /**
         * 5,聚宝盆:T5
         **/
        T5("聚宝盆", 5);

        public final int code;
        public final String value;
        private static Map<Integer, String> map = new HashMap<Integer, String>();

        CHANNEL(String value, int code) {
            this.code = code;
            this.value = value;
        }

        public static String getValue(Integer code) {
            if (null == code) {
                return null;
            }
            for (CashModel.CHANNEL auditStatus : CashModel.CHANNEL.values()) {
                if (auditStatus.code == code) {
                    return auditStatus.value;
                }
            }
            return null;
        }

        public static Integer getCode(String value) {
            if (null == value || "".equals(value)) {
                return null;
            }
            for (CashModel.CHANNEL auditStatus : CashModel.CHANNEL.values()) {
                if (auditStatus.value.equals(value)) {
                    return auditStatus.code;
                }
            }
            return null;
        }

        public static Map<Integer, String> getEnumMap() {
            if (map.size() == 0) {
                for (CashModel.CHANNEL auditStatus : CashModel.CHANNEL.values()) {
                    map.put(auditStatus.code, auditStatus.value);
                }
            }
            return map;
        }
    }

    /**
     * 1,1通过:T1<br>2,不通过:T2
     **/

    public enum AUDITSTATUS {

        /**
         * 1,1通过:T1
         **/
        T1("通过", 1),

        /**
         * 2,不通过:T2
         **/
        T2("不通过", 2);

        public final int code;
        public final String value;
        private static Map<Integer, String> map = new HashMap<Integer, String>();

        AUDITSTATUS(String value, int code) {
            this.code = code;
            this.value = value;
        }

        public static String getValue(Integer code) {
            if (null == code) {
                return null;
            }
            for (CashModel.AUDITSTATUS auditStatus : CashModel.AUDITSTATUS.values()) {
                if (auditStatus.code == code) {
                    return auditStatus.value;
                }
            }
            return null;
        }

        public static Integer getCode(String value) {
            if (null == value || "".equals(value)) {
                return null;
            }
            for (CashModel.AUDITSTATUS auditStatus : CashModel.AUDITSTATUS.values()) {
                if (auditStatus.value.equals(value)) {
                    return auditStatus.code;
                }
            }
            return null;
        }

        public static Map<Integer, String> getEnumMap() {
            if (map.size() == 0) {
                for (CashModel.AUDITSTATUS auditStatus : CashModel.AUDITSTATUS.values()) {
                    map.put(auditStatus.code, auditStatus.value);
                }
            }
            return map;
        }
    }


//
//    /**
//     * 格式化提现记录
//     *
//     * @param userId        操作用户id
//     * @param userBank      用户银行卡信息id
//     * @param account        操作金额
//     * @param actualArrival 实际到账金额（手续费自承情况）
//     * @param fee           手续费
//     * @param status        状态
//     * @return
//     */
//    public static Cash formatEntity(Integer userId, UserBank userBank, BigDecimal account, BigDecimal actualArrival, BigDecimal fee, STATUS status) {
//        Cash c = new Cash();
//        c.setUserId(userId);
//        c.setBankName(userBank.getBankName());
//        c.setBankNo(userBank.getBankNo());
//        c.setBranch(userBank.getBranch());
//        c.setAmount(account);
//        c.setActualArrival(actualArrival);
//        c.setFee(fee);
//        c.setStatus(status.code);
//        c.setOrderNo(OrderNoUtils.getSerialNumber());
//        return c;
//    }
}
